package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.serice.ArticleService;
import com.tarena.lbs.pojo.content.dto.ArticleContentDTO;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;

@RestController
@RequestMapping("/admin/content/")
@Slf4j
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //查询文章列表 手机端查询 和后台商家用户查询相同的接口但是参数不同
    @GetMapping("article/list")
    public Result<PageResult<ArticleContentDTO>> queryList(ArticleQuery query) throws BusinessException {
        PageResult<ArticleContentDTO> pageResult=articleService.queryList(query);
        return new Result<>(pageResult);
    }
    //新增文章到es
    @PostMapping("article/insert")
    public Result<Void> addArticle(ArticleContentParam param) throws BusinessException{
        articleService.addArticle(param);
        return Result.success();
    }
    //查询范围内文章标签集合
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<HashSet<String>> getArticleLables(ArticleQuery query) throws BusinessException{
        HashSet<String> articleLables=articleService.getArticleLables(query);
        return new Result<>(articleLables);
    }
    //获取文章详情
    @GetMapping("/admin/content/article/get")
    public Result<ArticleContentDTO> contentDetail(String id) throws BusinessException{
        ArticleContentDTO dto=articleService.getArticleDetail(id);
        return new Result<>(dto);
    }
}
